package org.flexlancer.utils
{
	import flash.filesystem.File;
	
	public class Path
	{
		public static function Combine(path1:String,path2:String):String{
			try{
				path1 = path1.split("\\").join("/");
				path2 = path2.split("\\").join("/");
				
				if ( path1.charAt(path1.length-1) != "/" )
					path1 += "/";
				
				return path1+path2;
			}catch(err:Error){
				throw err;
			}
			return "";
		}
		
		public static function GetDirectory(path:String):String{
			path = path.split("\\").join("/");
			return path.substr(0,path.lastIndexOf("/"));
		}
		public static function CreateDirectoryIfNotExists(fileObj:File,parmPath:String):void{
			try{
				var directoryPath:String = Path.GetDirectory(parmPath);
				if ( directoryPath == "" ) return;
				var file:File = fileObj.resolvePath(directoryPath);
				if ( !file.exists ){
					file.createDirectory();
				}
			}catch(err:Error){
				throw err;
			}
		}		
	}
}